package it.valeandre.omino.adapter;

import it.valeandre.omino.R;
import it.valeandre.omino.model.Match;
import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by Getta on 02/02/14.
 */
public class StatisticsAdapter extends BaseAdapter {

    private Match mMatch;
    private Handler mHandler = new Handler();
    private LayoutInflater mInflater;
    private Context mContext;


    public StatisticsAdapter(Context context, Match match) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mMatch = match;
    }

    public int getCount() {
        return 7;
    }

    public Integer getItem(int pos) {
        return pos;
    }

    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public boolean isEnabled(int position) {
        return false;
    }

    public View getView(int pos, View view, ViewGroup viewGroup) {

        view = mInflater.inflate(R.layout.statistics_item, null);
        TextView homeStatistic = (TextView) view.findViewById(R.id.statistics_item_home_data);
        TextView typeStatistic = (TextView) view.findViewById(R.id.statistics_item_data_type);
        TextView awayStatistic = (TextView) view.findViewById(R.id.statistics_item_away_data);

        switch (getItem(pos)) {
            case 1:
                homeStatistic.setText(mMatch.getHomeShots());
                awayStatistic.setText(mMatch.getAwayShots());
                typeStatistic.setText(mContext.getResources().getText(R.string.shoots));
                break;
            case 2:
                homeStatistic.setText(mMatch.getHomeShotsOnTarget());
                awayStatistic.setText(mMatch.getAwayShotsOnTarget());
                typeStatistic.setText(mContext.getResources().getText(R.string.shoots_on_target));
                break;
            case 3:
                homeStatistic.setText(mMatch.getHomeCorners());
                awayStatistic.setText(mMatch.getAwayCorners());
                typeStatistic.setText(mContext.getResources().getText(R.string.corner));
                break;
            case 4:
                homeStatistic.setText(mMatch.getHomeFouls());
                awayStatistic.setText(mMatch.getAwayFouls());
                typeStatistic.setText(mContext.getResources().getText(R.string.fouls));
                break;
            case 0:
                homeStatistic.setText(mMatch.getHalftimeHomeGoals());
                awayStatistic.setText(mMatch.getHalftimeAwayGoals());
                typeStatistic.setText(mContext.getResources().getText(R.string.first_half_goals));
                break;
            case 5:
                homeStatistic.setText(mMatch.getHomeYellowCards());
                awayStatistic.setText(mMatch.getAwayYellowCards());
                typeStatistic.setText(mContext.getResources().getText(R.string.yellow_cards));
                break;
            case 6:
                homeStatistic.setText(mMatch.getHomeRedCards());
                awayStatistic.setText(mMatch.getAwayRedCards());
                typeStatistic.setText(mContext.getResources().getText(R.string.red_cards));
                break;
            default:
                break;

        }

        if (homeStatistic.getText() ==  null || homeStatistic.getText().equals("")) {
            homeStatistic.setText("n.d.");
        }
        if (awayStatistic.getText() ==  null || awayStatistic.getText().equals("")) {
            awayStatistic.setText("n.d.");
        }

        return view;
    }
}
